package com.itheima.health.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.health.entity.PageResult;
import com.itheima.health.entity.QueryPageBean;
import com.itheima.health.entity.Result;
import com.itheima.health.pojo.CheckItem;
import com.itheima.health.pojo.Permission;
import com.itheima.health.service.PermissionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/*权限控制器
 */
@Slf4j
@RestController
@RequestMapping("/permission")
public class PermissionController {
    @Reference
    private PermissionService permissionService;

    /**
     * 分页查询
     * @param queryPageBean
     * @return
     */
    @GetMapping("/findPage")
    public Result findPage(QueryPageBean queryPageBean){
      PageResult pages= permissionService.findPage(queryPageBean);
      return new Result(true, "查询成功",pages);
    }

    /**
     * 编辑
     * @param permission
     * @return
     */
    @PostMapping("/edit")
    public Result update(@RequestBody Permission permission){
      permissionService.update(permission);
        return new Result(true, "修改成功");
    }


    /**
     * 添加
     * @param permission
     * @return
     */
    @PostMapping("/add")
    public Result add(@RequestBody Permission permission){
        permissionService.add(permission);
        return new Result(true, "添加成功");
    }


    /**
     * 删除
     * @param id
     * @return
     */
    @RequestMapping("/delete")
    public Result deleteById(Integer id){
        log.info("[删除]data:{}",id);
       permissionService.deleteById(id);
        return new Result(true, "删除成功");
    }


    @GetMapping("/findById")
    public  Result findById(Integer id){
        log.info("【更新前查询】:data{}",id);
       Permission permission= permissionService.findById(id);
       return new Result(true,"查询成功",permission);
    }
}
